//package sdk.webview.fmc.com.fmcsdk.util;
//
//import android.util.Log;
//
//import java.io.FileInputStream;
//import java.io.IOException;
//import java.net.InetAddress;
//import java.net.Socket;
//import java.security.KeyStore;
//import java.security.cert.Certificate;
//import java.security.cert.CertificateFactory;
//
//import javax.net.ssl.KeyManagerFactory;
//import javax.net.ssl.SSLContext;
//import javax.net.ssl.SSLSocket;
//import javax.net.ssl.SSLSocketFactory;
//import javax.net.ssl.TrustManagerFactory;
//
//public class TLSSocketFactory extends SSLSocketFactory {
//
//    private SSLSocketFactory internalSSLSocketFactory;
//
//    public TLSSocketFactory(SifrBl sifrbl) throws Exception {
//
//        FileInputStream fisTLS = new FileInputStream(sifrbl.SifrBlTls);
//        FileInputStream fis = new FileInputStream(sifrbl.SifrBlCert);
//
//        CertificateFactory cf = CertificateFactory.getInstance("X.509");
//
//        Certificate ca;
//        try {
//            ca = cf.generateCertificate(fisTLS);
//        } finally {
//            fisTLS.close();
//        }
//
//        //Create a KeyStore containing our trusted CAs
//        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
//        keyStore.load(null, null);
//        keyStore.setCertificateEntry("ca", ca);
//
//        KeyStore privatekeyStore = KeyStore.getInstance("PKCS12"); //
//        privatekeyStore.load(fis, sifrbl.SifrBlPass.toCharArray());
//        Log.i("jm_", "KeyStore size: " + keyStore.size());
//
//        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
//        tmf.init(keyStore);
//        Log.i("jm_", "TrustManagerFactory size: " + tmf.getTrustManagers().length);
//
//        KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509"); //x509
//        kmf.init(privatekeyStore, sifrbl.SifrBlPass.toCharArray());
//        Log.i("jm_", "KeyManagerFactory size: " + kmf.getKeyManagers().length);
//
//
//        SSLContext sslContext = SSLContext.getInstance("TLSv1.2");//TLSv1.2
//        sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
//
//        internalSSLSocketFactory = sslContext.getSocketFactory();
//
//    }
//
//    @Override
//    public String[] getDefaultCipherSuites() {
//        return internalSSLSocketFactory.getDefaultCipherSuites();
//    }
//
//    @Override
//    public String[] getSupportedCipherSuites() {
//        return internalSSLSocketFactory.getSupportedCipherSuites();
//    }
//
//    @Override
//    public Socket createSocket() throws IOException {
//        return enableTLSOnSocket(internalSSLSocketFactory.createSocket());
//    }
//
//    @Override
//    public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
//        return enableTLSOnSocket(internalSSLSocketFactory.createSocket(s, host, port, autoClose));
//    }
//
//    @Override
//    public Socket createSocket(String host, int port) throws IOException {
//        return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port));
//    }
//
//    @Override
//    public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException {
//        return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port, localHost, localPort));
//    }
//
//    @Override
//    public Socket createSocket(InetAddress host, int port) throws IOException {
//        return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port));
//    }
//
//    @Override
//    public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
//        return enableTLSOnSocket(internalSSLSocketFactory.createSocket(address, port, localAddress, localPort));
//    }
//
//    private Socket enableTLSOnSocket(Socket socket) {
//        if (socket != null && (socket instanceof SSLSocket)) {
//            ((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1.1", "TLSv1.2"});
//        }
//        return socket;
//    }
//}